<?php
namespace backend\models;
    use yii\base\Model;
    use yii\web\UploadedFile;
class UploadFile extends Model
{
       public $goods_img;
       public $goods_name;
       public $goods_price;
       public $goods_state;
       public $goods_follow;
       public $goods_pid;
       public $goods_id;
    protected function findModel($id)
    {
        if (($model = Goods::findOne($id)) !== null) {
            return $model;
        }

        //throw new NotFoundHttpException('The requested page does not exist.');
    }
       public function rules()
       {
           return [
               [['goods_img'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg'],
           ];
       }

    public function upload()
    {
        if ($this->validate()) {
            $this->goods_img->saveAs('../web/uploads/' . $this->goods_img->baseName . '.' . $this->goods_img->extension);
            return true;
        } else {
            return false;
        }
    }

}

